package com.gwnet.shop.controller;

import java.util.List;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.log.annotation.Log;
import com.gwnet.common.log.enums.BusinessType;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.shop.utils.AjaxResult;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gwnet.shop.domain.SysSchool;
import com.gwnet.shop.service.ISysSchoolService;

import javax.annotation.Resource;

/**
 * 学校Controller
 * 
 * @author 张万鹏
 * @date 2024-07-29
 */
@RestController
@RequestMapping("/school")
public class SysSchoolController extends MBaseController
{
    @Resource
    private ISysSchoolService sysSchoolService;

    /**
     * 查询学校列表
     */
    @SaCheckPermission("shop:school:list")
    @GetMapping("/list")
    public TableDataInfo list(SysSchool sysSchool)
    {
        startPage();
        List<SysSchool> list = sysSchoolService.selectSysSchoolList(sysSchool);
        return getDataTable(list);
    }


    /**
     * 获取学校详细信息
     */
    @SaCheckPermission("shop:school:query")
    @GetMapping(value = "/{schoolId}")
    public AjaxResult getInfo(@PathVariable("schoolId") Long schoolId)
    {
        return success(sysSchoolService.selectSysSchoolBySchoolId(schoolId));
    }

    /**
     * 新增学校
     */
    @SaCheckPermission("shop:school:add")
    @Log(title = "学校", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSchool sysSchool)
    {
        sysSchool.setCreateBy( LoginHelper.getUserId() );
        return toAjax(sysSchoolService.insertSysSchool(sysSchool));
    }

    /**
     * 修改学校
     */
    @SaCheckPermission("shop:school:edit")
    @Log(title = "学校", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSchool sysSchool)
    {
        sysSchool.setCreateBy( LoginHelper.getUserId() );
        return toAjax(sysSchoolService.updateSysSchool(sysSchool));
    }

    /**
     * 删除学校
     */
    @SaCheckPermission("shop:school:remove")
    @Log(title = "学校", businessType = BusinessType.DELETE)
	@DeleteMapping("/{schoolIds}")
    public AjaxResult remove(@PathVariable Long[] schoolIds)
    {
        return toAjax(sysSchoolService.deleteSysSchoolBySchoolIds(schoolIds));
    }
}
